import java.io.File;
import java.net.URL;
import java.util.Map;
import java.util.TreeMap;

/**
 * 读取国家资源文件xml形式，转换成IOS Properties的形式
 * Created by heyiyong on 2016/5/26.
 */
public class CountryReader {
    public static final String zhCountryFileName = "xml/strings_country_en.xml";
    public static final String enCountryFileName = "xml/strings_country_zh.xml";
    public static final String zhCountryProp = "strings_country_en.properties";
    public static final String enCountryProp = "strings_country_zh.properties";
    public static Map<String, String> zhKeyValMap = new TreeMap<>();
    public static Map<String, String> enKeyValMap = new TreeMap<>();

    public static void main(String[] args) throws Exception {
        // 1.1、找到文件源
        URL resource = XmlSorter.class.getResource(zhCountryFileName);
        File file = new File(resource.getFile());

        // 1.2、找到文件源
        URL resource2 = XmlSorter.class.getResource(enCountryFileName);
        File file2 = new File(resource2.getFile());

        // 2、读取文件，加入到treeMap里
        Utils.readXmlWithChild(zhKeyValMap, file);
        Utils.readXmlWithChild(enKeyValMap, file2);

        // 3、写出文件
        PropertiesReader.output(zhKeyValMap, zhCountryProp);
        PropertiesReader.output(enKeyValMap, enCountryProp);
    }
}
